package huang.homework10;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class StudentConcrol {
	//创建调用没交作业同学名单的方法；
		public int select_untest(){
			int i=0;
			BaseDao bd=new BaseDao();
			Connection con=bd.getCon();
			String sql="select *from testtable where take_test='undone'";
			try {
				PreparedStatement ps=con.prepareStatement(sql);
				ResultSet rs=ps.executeQuery();
				while(rs.next()){
					i++;
					System.out.println("没交作业的同学："+rs.getString("name"));
					
				}
				System.out.println("没交作业的人数为："+i);
				return i;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return i;
		}
		//调用作业完成并且优秀同学个数的方法
		public int selsect_welldone (){
			int i=0;
			BaseDao bd=new BaseDao();
			Connection con=bd.getCon();
			String sql="select *from testtable where take_test='well done'";
			try {
				PreparedStatement ps=con.prepareStatement(sql);
				ResultSet rs=ps.executeQuery();
				while(rs.next()){
					i++;
				}
				System.out.println("作业优秀的人数为："+i);
				return i;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return i;
		}
		//创建调用班级交作业同学的个数的方法；
			public int select_done(){
			int i=0;
			BaseDao bd=new BaseDao();
			Connection con=bd.getCon();
			String sql="select *from testtable where take_test='well done'or take_test='done'";
			try {
				PreparedStatement ps=con.prepareStatement(sql);
				ResultSet rs=ps.executeQuery();
				while(rs.next()){
					i++;
				}
				System.out.println("交作业的人数为："+i);
				return i;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return i;
				}
			//创建优秀率方法：
				public float wellRate(int welldone,int all){
				float rate=welldone/(float)all*100;
				System.out.println("整个班级的作业优秀率为："+rate+"%");
				return rate;
			}
}
